﻿
function click_reset(form) {
	form.reset();
	return false;
}

function check_del()
{
	if(confirm("请确认你要删除的记录！"))
		return true;
	else
		return false;
}

function DelCheck(str) {
	if(confirm(str))
		return true;
	else
		return false;
}


//选择和清除所有的复选框
function checkall(form)
{
	for(var i=0;i<form.elements.length;i++)
	{	
		var e = form.elements[i];
		if(form.elements[i].type=='checkbox' && form.chkall.value == '全选')
		{
			e.checked = true;
		}
		else
			e.checked = false;
	}
	
	if(form.chkall.value == '全选')
		form.chkall.value = '清除';
	else
		form.chkall.value = '全选';
}

//判断是否是日期
function isdate(strDate){

	var re=/^\d{4}-\d{1,2}-\d{1,2}$/;
	var r=strDate.match(re);
	if (r==null) return false;


   var strSeparator = "-"; //日期分隔符
   var strDateArray;
   var intYear;
   var intMonth;
   var intDay;
   var boolLeapYear;
   
   strDateArray = strDate.split(strSeparator);
   
   if(strDateArray.length!=3) return false;
   
   intYear = parseInt(strDateArray[0],10);
   intMonth = parseInt(strDateArray[1],10);
   intDay = parseInt(strDateArray[2],10);
   
   if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) return false;
   
   if(intMonth>12||intMonth<1) return false;
   
   if((intMonth==1||intMonth==3||intMonth==5||intMonth==7||intMonth==8||intMonth==10||intMonth==12)&&(intDay>31||intDay<1)) return false;
   
   if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30||intDay<1)) return false;
   
   if(intMonth==2){
      if(intDay<1) return false;
      
      boolLeapYear = false;
      if((intYear%100)==0){
         if((intYear%400)==0) boolLeapYear = true;
      }
      else{
         if((intYear%4)==0) boolLeapYear = true;
      }
      
      if(boolLeapYear){
         if(intDay>29) return false;
      }
      else{
         if(intDay>28) return false;
      }
   }
   
   return true;
}

function alertDate(input) {
	strDate = input.value;
	if (strDate == '') return;
	
	if(!isdate(strDate)) {
		var str = '';
		var new_date = new Date();
		new_date.setDate(parseInt(input.value) + new_date.getDate());
		if(new_date!='NaN') {
			str = new_date.getYear();
			str += '-';
			str += (new_date.getMonth()+1);
			str += '-';
			str += new_date.getDate();
			input.value = str;
			strDate = input.value;
		}
	}
	
	if(!isdate(strDate)) {
		alert("请输入正确地的日期格式[YYYY-MM-DD]。");
		input.focus();
		input.select();
	}
}

function istime(strTime)
{
    if(strTime.length==5)
    {
        if(strTime.charAt(2)!=':') return false;
		
		s = /[0-9][0-9][:][0-9][0-9]/;
		ok = s.exec(strTime);
		if (ok==null) {return false;};

		var HH = strTime.substring(0,2);
		if (HH<0||HH>23) {return false;};

		var MM = strTime.substring(3,5);
		if (MM<0||MM>59) {return false;};
    }
    else
    {
        return false;
    }

   return true;
}

function checkemail(input) {
	str = input.value;
	if ( str!="" )
	{
	if (str.indexOf('@', 0) == -1)
	{
		alert("这不是正确的e-mail address! 请再输入一次!");
		input.focus();
		input.select();}
	}
}

function isEmail(input) {
	str = input.value;
	if ( str=="" ) {
		return false;
	}
	if (str.indexOf('@', 0) == -1) {
		return false;
	}
	return true;
}

function callpage(htmlurl) {
	window.open(htmlurl,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=2,width=550,height=500');
	return false;
}

function isInt(e)
{
    var charCode=e.keyCode;
	status=charCode;
	if(charCode==45) return true;
	if(charCode>31 &&(charCode<48||charCode>57)) {
		//alert("请输入数字.");
		return false;
	}
	return true;
}

function checkInt(input) {
	var str = input.value;
	if(str.substring(0,1)=='-') str = str.substring(1,str.length);
	var re=/^\d{0,8}$/;
	var r=str.match(re);
	if (r == null) {
		alert('错误提示：请输入正确的数字！');
		input.focus();
		input.select();
	}

}

function isNumber(input) { 
	var str = input.value;
	if (str=='') return true;
	var re=/^\d{1,8}$|\.\d{1,4}$/;
	var r=str.match(re);
	if (r==null) {
		alert("错误提示：请输入正确的数值，小数点后最多保留四位小数。");
		input.focus();
		input.select();
	}
	return true;
}

function checkNumber(e) {
	var charCode = e.keyCode;
	if(charCode==45) return true;
	if(charCode==46) return true;
	if(charCode>31 &&(charCode<48||charCode>57)) {
		//alert("请输入数字.");
		return false;
	}
	return true;
}


function copyright() {
	document.write("<br><center>Copyright 2001-2010版权所有，All right Reserved </center><br>");
}

//显示、隐藏Search
function toSearch(){
	var args=toSearch.arguments;
	theObj=eval("document.all[\'"+args[0]+"\']");
	if(theObj) {
		if(theObj.style.visibility=='visible')
			theObj.style.visibility = 'hidden';
		else
			theObj.style.visibility = 'visible';
	}
}


function showCalendar() {
	
	var lastMouseX;
	var lastMouseY;
	var features;
	var width,height;
	width = 220;
	height = 200;
	if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
	lastMouseX = e.screenX;
	lastMouseY = e.screenY;
	if (lastMouseX - width < 0) {
		lastMouseX = width;
	}
	if (lastMouseY + height > screen.height) {
		lastMouseY -= (lastMouseY + height + 50) - screen.height;
	}
	lastMouseX -= width;
	lastMouseY += 10;
	features = "width="+width+",height="+height+",status=no,resizable=yes,"
	features +=	"screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;

	FileName = "../inc/Calendar.asp?formElt=" + arguments[0];
	vWinCal = window.open(FileName, "Calendar", features,false);
	vWinCal.focus();
}

function setComboxValue() {
	var Dwidth = 350;
	var Dheight = 260;
	
	var lastMouseX;
	var lastMouseY;
	var features;
	var FileName,formElt,showformElt, e;
	
	FileName = arguments[0];
	formElt = arguments[1];
	showformElt = arguments[2];
	if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
	lastMouseX = e.screenX;
	lastMouseY = e.screenY;
	
	if (lastMouseX - Dwidth < 0) {
		lastMouseX = Dwidth;
	}
	if (lastMouseY + Dheight > screen.height) {
		lastMouseY -= (lastMouseY + Dheight + 50) - screen.height;
	}
	lastMouseX -= Dwidth;
	lastMouseY += 10;
	features = "dialogWidth:"+Dwidth+"px;dialogHeight:"+Dheight+"px; scroll:1; help:0; status:No; fullscreen;resizable=yes;";
	features +=	"screenX:" + lastMouseX + ";dialogLeft:" + lastMouseX + ";screenY:" + lastMouseY + ";dialogTop:" + lastMouseY;

	

	rv=window.showModalDialog(FileName,null,features);
	//rv=window.showModalDialog(FileName,null,"dialogWidth:"+Dwidth+"px;dialogHeight:"+Dheight+"px;center:1;scroll:0;help:0;status:0");
	if ( rv == null) return;
	if ( showformElt != "" && formElt != "") {
		var i = formElt.indexOf('.');
		var formName,formEltName;
		//设置显示的值
		if( rv[0] == "") {
			//清空ID
			formName = formElt.substring(0,i);
			formEltName = formElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = "";
			//清空显示的值
			formName = showformElt.substring(0,i);
			formEltName = showformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = "";
		}
		else {
			//设置ID
			formName = formElt.substring(0,i);
			formEltName = formElt.substring(i+1);
			
			document.forms[formName].elements[formEltName].value = ignoreSpaces(rv[0]);
			//设置显示的值
			formName = showformElt.substring(0,i);
			formEltName = showformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = ignoreSpaces(rv[1]);
		}
	}
	return;
}

function setComboxValue3() {
	var Dwidth = 190;
	var Dheight = 260;
	
	var lastMouseX;
	var lastMouseY;
	var features;
	var FileName,formElt,showformElt, e;
	
	FileName = arguments[0];
	formElt = arguments[1];
	showformElt = arguments[2];
	priceformElt = arguments[3];
	if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
	lastMouseX = e.screenX;
	lastMouseY = e.screenY;
	
	if (lastMouseX - Dwidth < 0) {
		lastMouseX = Dwidth;
	}
	if (lastMouseY + Dheight > screen.height) {
		lastMouseY -= (lastMouseY + Dheight + 50) - screen.height;
	}
	lastMouseX -= Dwidth;
	lastMouseY += 10;
	features = "dialogWidth:"+Dwidth+"px;dialogHeight:"+Dheight+"px; scroll:0; help:0; status:No; fullscreen;";
	features +=	"screenX:" + lastMouseX + ";dialogLeft:" + lastMouseX + ";screenY:" + lastMouseY + ";dialogTop:" + lastMouseY;

	

	rv=window.showModalDialog(FileName,null,features);
	//rv=window.showModalDialog(FileName,null,"dialogWidth:"+Dwidth+"px;dialogHeight:"+Dheight+"px;center:1;scroll:0;help:0;status:0");
	if ( rv == null) return;
	if ( showformElt != "" && formElt != "") {
		var i = formElt.indexOf('.');
		var formName,formEltName;
		//设置显示的值
		if( rv[0] == "") {
			//清空ID
			formName = formElt.substring(0,i);
			formEltName = formElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = "";
			//清空显示的值
			formName = showformElt.substring(0,i);
			formEltName = showformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = "";

			formName = priceformElt.substring(0,i);
			formEltName = priceformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = "";
		}
		else {
			//设置ID
			formName = formElt.substring(0,i);
			formEltName = formElt.substring(i+1);
			
			document.forms[formName].elements[formEltName].value = ignoreSpaces(rv[0]);
			//设置显示的值
			formName = showformElt.substring(0,i);
			formEltName = showformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = ignoreSpaces(rv[1]);

			formName = priceformElt.substring(0,i);
			formEltName = priceformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = ignoreSpaces(rv[2]);
		}
	}
	return;
}

function setComboxValue1() {
	var Dwidth = 350;
	var Dheight = 260;
	
	var lastMouseX;
	var lastMouseY;
	var features;
	var FileName,formElt,showformElt, e;
	
	FileName = arguments[0];
	formElt = arguments[1];
	showformElt = arguments[2];
	if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
	lastMouseX = e.screenX;
	lastMouseY = e.screenY;
	
	if (lastMouseX - Dwidth < 0) {
		lastMouseX = Dwidth;
	}
	if (lastMouseY + Dheight > screen.height) {
		lastMouseY -= (lastMouseY + Dheight + 50) - screen.height;
	}
	lastMouseX -= Dwidth;
	lastMouseX += 200;
	lastMouseY += 10;
	features = "dialogWidth:"+Dwidth+"px;dialogHeight:"+Dheight+"px; scroll:0; help:0; status:No; fullscreen;";
	features +=	"screenX:" + lastMouseX + ";dialogLeft:" + lastMouseX + ";screenY:" + lastMouseY + ";dialogTop:" + lastMouseY;

	

	rv=window.showModalDialog(FileName,null,features);
	//rv=window.showModalDialog(FileName,null,"dialogWidth:"+Dwidth+"px;dialogHeight:"+Dheight+"px;center:1;scroll:0;help:0;status:0");
	if ( rv == null) return;
	if ( showformElt != "" && formElt != "") {
		var i = formElt.indexOf('.');
		var formName,formEltName;
		//设置显示的值
		if( rv[0] == "") {
			//清空ID
			formName = formElt.substring(0,i);
			formEltName = formElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = "";
			//清空显示的值
			formName = showformElt.substring(0,i);
			formEltName = showformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = "";
		}
		else {
			//设置ID
			formName = formElt.substring(0,i);
			formEltName = formElt.substring(i+1);
			
			document.forms[formName].elements[formEltName].value = ignoreSpaces(rv[0]);
			//设置显示的值
			formName = showformElt.substring(0,i);
			formEltName = showformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = ignoreSpaces(rv[1]);
		}
	}
	return;
}

//清除空格
function ignoreSpaces(string) {
	var temp = "";
	string = '' + string;
	splitstring = string.split("　");
	for(i = 0; i < splitstring.length; i++)
		temp += splitstring[i];
	return temp;
}

var objPrevElement = null;
function ChangeColor() {
	source=event.srcElement;

	if(objPrevElement!=null && objPrevElement.tagName=='TR')
	objPrevElement.style.backgroundColor='#EEEEEE';

	//for(i in document.all){
	//	if(document.all[i].t==1){//用户触发:重新设置属性
	//		document.all[i].style.backgroundColor='#EEEEEE';
	//	}
	//}
	//if(source.tagName=="INPUT") {
		//if(source.checked)
	//}
	if(source.tagName=="INPUT") return;
	if(source.tagName=="IMG") return;
	if(source.tagName=="TABLE") return;
	while(source.tagName!="TR") {
		source=source.parentElement;
	}
	if (source.style.backgroundColor!='#CFDFFF'&&source.id!="ignore") {
		source.style.backgroundColor='#CFDFFF';
		objPrevElement=event.srcElement.parentElement;
	} else {
		source.style.backgroundColor='#EEEEEE';
	}
}

//按取消关闭窗口
function onClose() {
	if(event.keyCode==27) window.close();
	return true;
}


function openSelect() {
	var width = 520;
	var height = 400;
	var features;
	var e,FileName;
	FileName = arguments[0];
	features = "width="+width+",height="+height+",status=no,resizable=auto,scrollbars=yes"
	//features +=	"screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
	selWin = window.open(FileName, "selectWindow", features,false);
	selWin.focus();
}


function Find_Customer() {
	var Dwidth = 350;
	var Dheight = 420;
	
	var lastMouseX;
	var lastMouseY;
	var features;
	var FileName,formElt,showformElt, e;
	
	FileName = arguments[0];
	formElt = arguments[1];
	showformElt = arguments[2];
	if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
	lastMouseX = e.screenX;
	lastMouseY = e.screenY;
	
	if (lastMouseX - Dwidth < 0) {
		lastMouseX = Dwidth;
	}
	if (lastMouseY + Dheight > screen.height) {
		lastMouseY -= (lastMouseY + Dheight + 50) - screen.height;
	}
	lastMouseX -= Dwidth;
	lastMouseX += 200;
	lastMouseY += 10;
	features = "dialogWidth:"+Dwidth+"px;dialogHeight:"+Dheight+"px; scroll:0; help:0; status:No; scroll:1;fullscreen;";
	features +=	"screenX:" + lastMouseX + ";dialogLeft:" + lastMouseX + ";screenY:" + lastMouseY + ";dialogTop:" + lastMouseY;

	rv=window.showModalDialog(FileName,null,features);
	if ( rv == null) return;
	if ( showformElt != "" && formElt != "") {
		var i = formElt.indexOf('.');
		var formName,formEltName;
		//设置显示的值
		if( rv[0] == "") {
			//清空ID
			formName = formElt.substring(0,i);
			formEltName = formElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = "";
			//清空显示的值
			formName = showformElt.substring(0,i);
			formEltName = showformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = "";
		}
		else {
			//设置ID
			formName = formElt.substring(0,i);
			formEltName = formElt.substring(i+1);
			
			document.forms[formName].elements[formEltName].value = ignoreSpaces(rv[0]);
			//设置显示的值
			formName = showformElt.substring(0,i);
			formEltName = showformElt.substring(i+1);
			document.forms[formName].elements[formEltName].value = ignoreSpaces(rv[1]);
		}
	}
	return;
}






